package org.zhxy.core.quality.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.zhxy.entity.quality.Student;
import org.zhxy.entity.quality.UserStudent;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentManagerMapper extends BaseMapper<Student>{

    @Select("<script> " +
            " SELECT u.*,s.* " +
            " FROM pe_user u,qu_student s " +
            " WHERE u.`id` = s.`id` " +
            " ORDER BY s.`study_type` ASC,s.`classes_id` DESC " +
            " LIMIT #{map.page},#{map.size} " +
            " </script>")
    List<UserStudent> searchAllStudentList(@Param("map") Map<String, Object> map);

    @Select("<script>" +
            " SELECT COUNT(0) AS total FROM qu_student " +
            "</script>")
    long getTotalCount(@Param("map")Map<String, Object> map);

    @Select("<script> SELECT u.*,s.* " +
            " FROM pe_user u,qu_student s " +
            " WHERE s.`classes_id` IN ( " +
            "  SELECT c.`id` " +
            "  FROM qu_teacher_classes tc, sc_teacher t , qu_classes c " +
            "  WHERE t.`id` = tc.`teacher_id` " +
            "  AND tc.`classes_id` = c.`id` " +
            "  AND tc.`status` = '1' " +
            "  AND t.id = #{map.id} " +
            " ) " +
            " AND u.`id` = s.`id` " +
            " AND u.`type` = '2' " +
            " ORDER BY s.`study_type` DESC, s.`classes_id` DESC " +
            " LIMIT #{map.page},#{map.size}" +
            "</script>")
    List<UserStudent> searchStudentListByTeacherClasses(@Param("map")Map<String, Object> map);

    @Select("<script>" +
            " SELECT COUNT(0) " +
            " FROM pe_user u,qu_student s " +
            " WHERE s.`classes_id` IN ( " +
            "  SELECT c.`id` " +
            "  FROM qu_teacher_classes tc, sc_teacher t , qu_classes c " +
            "  WHERE t.`id` = tc.`teacher_id` " +
            "  AND tc.`classes_id` = c.`id` " +
            "  AND tc.`status` = '1' " +
            "  AND t.id = #{map.id} " +
            " ) " +
            " AND u.`id` = s.`id` " +
            " AND u.`type` = '2'" +
            " </script>")
    long getTotalByTeacherClasses(@Param("map")Map<String, Object> map);
}
